<?php
declare (strict_types = 1);

namespace app\admin\middleware;
use think\facade\Cookie;
use think\facade\Session;


class LoginCheck
{
    use \liliuwei\think\Jump;
    public function handle($request, \Closure $next)
    {
        $code = Cookie::get('user');

        if(!isset($code)){  //判断是否存在Cookie
            $this->error('未登录，请登录','/admin/index/index');
        }

        $user = Session::get($code);
        if(empty($user)){   //如果获取不到对应的session就跳回登录
            $this->error('秘钥错误,请重新登录','/admin/index/index');
        }
        $request->user=$user;
        return $next($request);
    }
}
